package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.projeto.sakila.bean.Customer;

public class CustomerDao {

	private SessionFactory sessionFactory;
	private Session session;

	public CustomerDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	
	public long buscarCustomer(){
		long tempoInicial = System.currentTimeMillis();
		List<Customer> listaCustomer = new ArrayList<>();
		try{
			session = sessionFactory.openSession();			 
			listaCustomer = session.createQuery("from Customer").list();			
			session.close();
		} catch (Exception e){
			System.err.println("Error");
		}
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}
	
	public void listarActor(List<Customer> lista){
		System.out.println("---------------------------");
		for (Customer customer : lista) {
			System.out.println("ID : " + customer.getId());
			System.out.println("Fist Name : " + customer.getFirstName());
			System.out.println("Last Name : " + customer.getLastName());
			System.out.println("Email : " + customer.getEmail());
			System.out.println("Active : " + customer.getActive());
			//TODO:falta campos

			System.out.println("---------------------------");
		}
	}
}
